package collectionDemo.arraylistdemo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: Jie
 * @Date: 2019/1/17 17:44
 * @Function :list 转 array 后进行比较
 */
public class ListToArray {
    public void main(String[] args) {

        List<Integer> mOneList = new ArrayList<>();


        mOneList.add(1);
        mOneList.add(3);
        mOneList.add(2);
//        mOneList.add(null);//todo null 导致排序错误java.lang.NullPointerException  at java.util.Arrays.sort(Arrays.java:1246)
        Integer[] oneArray = (Integer[]) mOneList.toArray(new Integer[mOneList.size()]);
        Arrays.sort(oneArray);

        List<Integer> mTwoList = new ArrayList<>();
        mTwoList.add(1);
        mTwoList.add(2);
        mTwoList.add(3);
        Integer[] twoArray = (Integer[]) mTwoList.toArray(new Integer[mTwoList.size()]);
        Arrays.sort(twoArray);
        System.out.println(Arrays.equals(oneArray,twoArray));

         printArray(oneArray);
    }

    private static void printArray(Object[] oneArray) {
        System.out.println("print start ********");
        for (Object obj: oneArray) {
            System.out.print(obj);
            System.out.print(",");
        }
        System.out.println("print end ********");
    }

}
